package com.ty.springbootjapthymeleaf.entity;

import jakarta.persistence.*;

import java.io.Serializable;

/**
 * User
 *
 * @aurhor Administrator  whs
 * @since 2024/8/28
 */
@Entity // 用来标记一个数据库表对应的实体，默认和数据库中创建的表名和类名默认一致 对应数据库中的一个表，用此注解标记 pojo 是一个 JPA 实体
@Table(name = "sys_user") // 用来标记一个数据库表对应的实体，默认和数据库中创建的表名和类名默认一致 只能标注在实体的class处 表示实体对应的数据库表的信息
//@Data
//@NamedQueries(@NamedQuery(name = "User.findUsersByName",query = "select u from User u where u.usrName = ?1")) // 命名QL查询
public class User implements Serializable {

    @Id // 映射到数据库表的主键的属性 一个实体只能有一个属性被映射为主键
    @GeneratedValue(strategy = GenerationType.IDENTITY)  // 主键生成策略
    @Column(name = "usr_id")
    private Long usrId; // 编号
    @Column(name = "usr_name") // 数据库表中该字段的详情定义
    private String usrName; // 姓名
    @Column(name = "usr_password")
    private String usrPassword; // 密码

    // 添加关联Role对象
    @ManyToOne(targetEntity = Role.class)  // 表示多对一关联
    @JoinColumn(name = "usr_role_id")  // 注解映射关联的外键字段 ， 如不指定会生成一张新表维护两个对象之间的关系
    private Role role;


//    @Column(name = "usr_role_id")
//    private Long usrRoleId; // 角色编号


    @Column(name = "usr_flag")
    private Long usrFlag; // 状态

    public User(String usrName, String usrPassword, Role role, Long usrFlag) {
        this.usrName = usrName;
        this.usrPassword = usrPassword;
        this.role = role;
        this.usrFlag = usrFlag;
    }

    public User() {
    }




    public Role getRole() {
        return role;
    }

    public void setRole(Role role) {
        this.role = role;
    }

    @Override
    public String toString() {
        return "User{" +
                "usrId=" + usrId +
                ", usrName='" + usrName + '\'' +
                ", usrPassword='" + usrPassword + '\'' +
//                ", usrRoleId=" + usrRoleId +
                ", role=" + role +
                ", usrFlag=" + usrFlag +
                '}';
    }

    public Long getUsrId() {
        return usrId;
    }

    public void setUsrId(Long usrId) {
        this.usrId = usrId;
    }

    public String getUsrName() {
        return usrName;
    }

    public void setUsrName(String usrName) {
        this.usrName = usrName;
    }

    public String getUsrPassword() {
        return usrPassword;
    }

    public void setUsrPassword(String usrPassword) {
        this.usrPassword = usrPassword;
    }

//    public Long getUsrRoleId() {
//        return usrRoleId;
//    }
//
//    public void setUsrRoleId(Long usrRoleId) {
//        this.usrRoleId = usrRoleId;
//    }

    public Long getUsrFlag() {
        return usrFlag;
    }

    public void setUsrFlag(Long usrFlag) {
        this.usrFlag = usrFlag;
    }
}
